import O1HD, {modules, services} from "../../engines/gameEngine";
import {GAME_MODE} from "../../engines/managers/gameContent/gameMode_json";
import {VIBRATE_TYPE} from "../../engines/services/miniGameContent/miniApp";
import {textFilter} from "../test/filterWord";
import {dataField} from "../../engines/services/miniGameContent/dataField";
import cellLayerMiniGameJump from "../../O1ModuleRes/preload/cellLayerMiniGameJump";

export namespace Desk {
    //单个操作
    import RANK_ID = dataField.RANK_ID;

    export interface DisplayItem {
        id: string;
        name: string;
        //图标
        icon?: string;
        //点击事件
        onClickEvent: (event?: any, custom?: string) => void;
    }

    //分组信息
    export interface DisGroup {
        id: string;
        name: string;
        disItemIdList: string[];
    }

    export function searchIdsOfName(searchStr: string): string[] {
        let ids: string[] = [];
        //
        constItems.forEach(value => {
            if (value.name.includes(searchStr) || value.id.includes(searchStr)) {
                ids.push(value.id);
            }
        });
        return ids;
    }

    export function getDisPlayItemList(findId?: string): DisplayItem[] | DisplayItem {
        //
        if (!findId) {
            return constItems;
        }
        //
        for (let item of constItems) {
            if (item.id == findId) return item;
        }
        return null;
    }

    export function getDeskDisplayListInfo(): DisGroup[] {
        return [
            {
                id: 'display001',
                name: 'UI操作',
                disItemIdList: ['item001', 'item002', 'item003', 'item004', 'item005', 'item013', 'item020',
                    'item021', 'item022', 'item028'],
            },
            {
                id: 'display002',
                name: '平台相关',
                disItemIdList: ['item005', 'item006', 'item007', 'item008', 'item005', 'item011', 'item014', 'item015',
                    'item016', 'item017', 'item018', 'item019', 'item023', 'item025', 'item026', 'item029', 'item030',
                    'item031', 'item032', 'item033', 'item034', 'item035', 'item036', 'item037', 'item038'],
            },
            {
                id: 'display003',
                name: '框架内容',
                disItemIdList: ['item039'],
            },
            {
                id: 'display004',
                name: '内置模式',
                disItemIdList: ['item012', 'item024', 'item027'],
            }
        ]
    }

    //
    const constItems: DisplayItem[] = [
        {
            id: 'item001',
            name: '确认框',
            onClickEvent: (event, custom) => {
                modules().uiControlModule.showDialogBox(
                    '温馨提示',
                    '告诉你一个消息',
                    false,
                    null,
                    null,
                    '我知道了');
            }
        },
        {
            id: 'item002',
            name: '确定取消框',
            onClickEvent: (event, custom) => {
                O1HD.getModules().uiControlModule.showDialogBox('温馨提示', '你需要选择一个选项', true, (isOk) => {
                    O1HD.getModules().uiControlModule.showMessageBox(isOk ? '确认了' : '取消了');
                }, null, 'A、确认', 'B、取消');
            }
        },
        {
            id: 'item003',
            name: '看一次视频',
            onClickEvent: (event, custom) => {
                O1HD.getModules().uiControlModule.showDialogBox('温馨提示', '你需要观看一个视频来得到一个东西', true, (isOk) => {
                    O1HD.getModules().uiControlModule.showMessageBox(isOk ? '看完' : '没看完');
                }, null, '看吧', '忍痛不看', 1);
            }
        },
        {
            id: 'item004',
            name: '看多次视频',
            onClickEvent: (event, custom) => {
                O1HD.getModules().uiControlModule.showDialogBox('温馨提示', '你需要观看多个视频来得到一个东西', true, (isOk) => {
                    O1HD.getModules().uiControlModule.showMessageBox(isOk ? '看完' : '没看完');
                }, null, '看吧', '忍痛不看', 2 + Math.floor(Math.random() * 3));
            }
        },
        {
            id: 'item005',
            name: '3秒加载完',
            onClickEvent: (event, custom) => {
                O1HD.getModules().uiControlModule.showLoading();
                O1HD.Component().scheduleOnce(() => {
                    O1HD.getModules().uiControlModule.hideLoading();
                }, 3);
            }
        },
        {
            id: 'item006',
            name: '开始直播',
            onClickEvent: (event, custom) => {
                O1HD.getServices().miniGameSrv.getAppApiInstance().operateGameLive();
            }
        },
        {
            id: 'item007',
            name: 'banner广告',
            onClickEvent: (event, custom) => {
                O1HD.getModules().uiControlModule.showDialogBox_Banner_MC("疯狂砸金蛋",
                    () => {
                        O1HD.getModules().uiControlModule.showMessageBox('点完');
                    }, null);
            }
        },
        {
            id: 'item008',
            name: 'native广告',
            onClickEvent: (event, custom) => {
                O1HD.getModules().uiControlModule.showDialogBox_Banner_MC("疯狂砸金蛋",
                    () => {
                        O1HD.getModules().uiControlModule.showMessageBox('点完');
                    }, null);
            }
        },
        {
            id: 'item011',
            name: '添加桌面',
            onClickEvent: (event, custom) => {
                O1HD.getServices().miniGameSrv.getAppApiInstance().addShortcut().then();
            }
        },
        {
            id: 'item012',
            name: '迷宫',
            onClickEvent: (event, custom) => {
                O1HD.getManagers().gameMgr.selectMode(GAME_MODE.DFS);
            }
        },
        {
            id: 'item013',
            name: '画板预制',
            onClickEvent: (event, custom) => {
                modules().uiControlModule.showFramePrefab('preload/control/o1DrawBoard', null);
            }
        },
        {
            id: 'item014',
            name: '视频列表',
            onClickEvent: (event, custom) => {
                modules().uiControlModule.showFramePrefab('preload/control/shareVideoRank', null);
            }
        },
        {
            id: 'item015',
            name: '订阅消息',
            onClickEvent: (event, custom) => {
                O1HD.getServices().miniGameSrv.getAppApiInstance().subscribeMessage();
            }
        },
        {
            id: 'item016',
            name: '添加到收藏',
            onClickEvent: (event, custom) => {
                O1HD.getServices().miniGameSrv.getAppApiInstance().showAddFavoriteGuide();
            }
        },
        {
            id: 'item017',
            name: '互跳1',
            onClickEvent: (event, custom) => {
                window['tt'] &&
                window['tt'].setMoreGamesInfo({
                    appLaunchOptions: [
                        {
                            appId: "tt3a5c4ce1a56771f4",
                            query: "foo=bar&baz=qux",
                            extraData: {}
                        },
                        {
                            appId: "tt1fed695080d61c40",
                            query: "foo=bar&baz=qux",
                            extraData: {}
                        }
                    ],
                })
            }
        },
        {
            id: 'item018',
            name: '互跳2',
            onClickEvent: (event, custom) => {
                if (window['tt'] == null) {
                    return;
                }
                const banner = window['tt'].createMoreGamesBanner({
                    style: {
                        left: 20,
                        top: 40,
                        width: 150,
                        height: 40,
                    },
                    appLaunchOptions: [
                        {
                            appId: "tt3a5c4ce1a56771f4",
                            query: "foo=bar&baz=qux",
                            extraData: {}
                        },
                        {
                            appId: "tt1fed695080d61c40",
                            query: "foo=bar&baz=qux",
                            extraData: {}
                        }
                    ],
                })
                banner.show();
                banner.onTap(() => {
                    console.log("点击跳转游戏盒子");
                });
            }
        },
        {
            id: 'item019',
            name: '互跳3',
            onClickEvent: (event, custom) => {
                if (window['tt'] == null) {
                    return;
                }
                const btn = window['tt'].createMoreGamesButton({
                    type: "image",
                    image: "images/more_games_btn.png",
                    actionType: "box",
                    style: {
                        left: 20,
                        top: 40,
                        width: 150,
                        height: 40,
                        lineHeight: 40,
                        backgroundColor: "#ff0000",
                        textColor: "#ffffff",
                        textAlign: "center",
                        fontSize: 16,
                        borderRadius: 4,
                        borderWidth: 1,
                        borderColor: "#ff0000"
                    },
                    appLaunchOptions: [
                        {
                            appId: "tt3a5c4ce1a56771f4",
                            query: "foo=bar&baz=qux",
                            extraData: {}
                        },
                        {
                            appId: "tt1fed695080d61c40",
                            query: "foo=bar&baz=qux",
                            extraData: {}
                        }
                        // {...}
                    ],
                    onNavigateToMiniGame(res) {
                        console.log("跳转其他小游戏", res);
                    }
                });

                btn.onTap(() => {
                    console.log("点击更多游戏");
                });
            }
        },
        {
            id: 'item020',
            name: '新手手势',
            onClickEvent: (event, custom) => {
                O1HD.getModules().uiControlModule.showFramePrefab('public/prefab/GuideFinger');
            }
        },
        {
            id: 'item021',
            name: '星星粒子',
            onClickEvent: (event, custom) => {
                O1HD.getModules().uiControlModule.showFramePrefab('public/prefab/ef_Star');
            }
        },
        {
            id: 'item022',
            name: '彩带粒子',
            onClickEvent: (event, custom) => {
                O1HD.getModules().uiControlModule.showFramePrefab('public/prefab/ef_Confetti');
            }
        },
        {
            id: 'item023',
            name: '录音变声',
            onClickEvent: (event, custom) => {
                O1HD.getModules().uiControlModule.showFramePrefab('preload/control/recordVoiceChange');
            }
        },
        {
            id: 'item024',
            name: '炫彩粒子',
            onClickEvent: (event, custom) => {
                O1HD.getManagers().gameMgr.selectMode(GAME_MODE.NORMAL);
            }
        },
        {
            id: 'item025',
            name: '短振动',
            onClickEvent: (event, custom) => {
                O1HD.getServices().miniGameSrv.getAppApiInstance().vibrate(VIBRATE_TYPE.SHORT);
            }
        },
        {
            id: 'item026',
            name: '长振动',
            onClickEvent: (event, custom) => {
                O1HD.getServices().miniGameSrv.getAppApiInstance().vibrate(VIBRATE_TYPE.LONG);
            }
        },
        {
            id: 'item027',
            name: '内网聊天',
            onClickEvent: (event, custom) => {
                O1HD.getManagers().gameMgr.selectMode(GAME_MODE.TALK_ROOM);
            }
        },
        {
            id: 'item028',
            name: '版本公告',
            icon: '1',
            onClickEvent: (event, custom) => {
                O1HD.getManagers().gameMgr.showVersionNotice();
            }
        },
        {
            id: 'item029',
            name: '敏感词汇',
            onClickEvent: (event, custom) => {
                let t = Date.now();
                console.log(textFilter('我说逢九必乱，电击枪'));
                console.log(Date.now() - t);
            }
        },
        {
            id: 'item030',
            name: '开始录屏',
            onClickEvent: (event, custom) => {
                O1HD.getServices().miniGameSrv.getAppApiInstance().gameRecordStart({duration: 60});
            }
        },
        {
            id: 'item031',
            name: '停止录屏',
            onClickEvent: (event, custom) => {
                let ok = O1HD.getServices().miniGameSrv.getAppApiInstance().gameRecordStop();
                if (!ok) {
                    O1HD.getModules().uiControlModule.showMessageBox('停止失败 录屏时间过短');
                }
            }
        },
        {
            id: 'item032',
            name: '分享录屏',
            onClickEvent: (event, custom) => {
                O1HD.getServices().miniGameSrv.getAppApiInstance().shareGameRecordVideo();
            }
        },
        {
            id: 'item033',
            name: '提交排行榜',
            onClickEvent: (event, custom) => {
                console.log('发送数据域');
                services().miniGameSrv.getAppApiInstance().commitRank(RANK_ID.TRIPLE_JUMP, 100).then(value => {
                    if (!value) {
                        modules().uiControlModule.showMessageBox('提交分数到排行榜失败');
                    }
                });
            }
        },
        {
            id: 'item034',
            name: '展示排行榜',
            onClickEvent: (event, custom) => {
                console.log('展示数据域');
                O1HD.emit('hall.onRankShow');
                services().miniGameSrv.getAppApiInstance().showRank(RANK_ID.TRIPLE_JUMP).then(value => {
                    if (!value) {
                        modules().uiControlModule.showMessageBox('获取排行榜数据失败');
                    }
                });
            }
        },
        {
            id: 'item035',
            name: '发送埋点',
            onClickEvent: (event, custom) => {
                console.log('发送埋点');
                O1HD.getServices().miniGameSrv.getAppApiInstance().reportAnalytics('0', 1);
            }
        },
        {
            id: 'item036',
            name: '格子跳转',
            onClickEvent: (event, custom) => {
                modules().uiControlModule.showFramePrefab('preload/cellLayerMiniGameJump', null, false, node => {
                    //可设置位置
                    // node.getComponent(cellLayerMiniGameJump).setPosition([cc.v2(x,y), cc.v2(x,y)]);
                });
            }
        },
        {
            id: 'item037',
            name: '轮播弹窗跳转',
            onClickEvent: (event, custom) => {
                modules().uiControlModule.showFramePrefab('preload/scrollMiniGameJump');
            }
        },
        {
            id: 'item038',
            name: '侧拉栏跳转',
            icon: '2',
            onClickEvent: (event, custom) => {
                modules().uiControlModule.showFramePrefab('preload/dialogMiniGameJump');
            }
        },
        {
            id: 'item039',
            icon: 'Option',
            name: '游戏设置',
            onClickEvent: (event, custom) => {
                modules().uiControlModule.showFramePrefab('preload/control/gameSetting');
            }
        }
    ];
}





























